const lodash = require("lodash");
class PagerHelper {
  constructor(href, options = [10, 20, 50], pageNum = 1, pageSize = 10) {
    this.href = href;
    this.options = options;
    this.pageNum = pageNum;
    this.pageSize = pageSize;
    //把数组按PageSize拆分成若干个数组
  }

  setCount(count) {
    //数组
    this.count = count;
    //this.total 为一共的页数
    if (!lodash.isNumber(this.pageNum)) {
      this.pageNum = parseInt(this.pageNum);
    }
    if (!lodash.isNumber(this.pageSize)) {
      this.pageSize = parseInt(this.pageSize);
    }
    if (this.count % this.pageSize === 0) {
      this.total = Math.floor(this.count / this.pageSize);
    } else {
      this.total = Math.floor(this.count / this.pageSize) + 1;
    }
    // let pageNum = 0;//当前页码
    this.firstNum = 1; //首页码1
    this.lastNum = this.total; //尾页码
    this.preNum = this.pageNum - 1; //上一页页码
    if (this.preNum <= 0) {
      this.preNum = 1;
    }
    this.nextNum = this.pageNum + 1; //下一页页码
    if (this.nextNum >= this.total) {
      this.nextNum = this.total;
    }

    if (this.pageNum > this.total) {
      this.pageNum = this.total;
    }
    //把数组按PageSize拆分成若干个数组
    // this.pageData = lodash.chunk(count, this.pageSize);
  }
  /*
  返回一个按pagesize分割的的数组
*/

}

//封装成了对象了{}，new成一个对象，只有一次
module.exports = {
  pagerHelper: new PagerHelper(),
};
